package com.zxj.shop.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zxj.shop.admin.entity.Role;
import com.zxj.shop.admin.entity.RolePermission;
import com.zxj.shop.admin.entity.UserRole;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMapper extends BaseMapper<Role> {

    @Select("select r.* from sys_user_role ur,sys_role r where ur.role_id = r.id and ur.user_id=#{userId}")
    List<Role> getUserRoles(String userId);

    @Insert({"insert into sys_role_permission(role_id,permission_id) values(#{roleId}, #{permissionId})" })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int createRolePermission(RolePermission userRole);

}
